home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #2
/
Monster Media No. 2 (Monster Media)(1994).ISO
/
clipper
/
mrddem.zip
/
WINDOW.PRG
< prev
Wrap
Text File
|
1994-06-29
|
20KB
|
495 lines
#include "class(y).ch"
#Include "Box.ch"
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Class│Window │
│ Purpose│A Window Class to creat windows on the screen. To give them │
│ │headers, titles and anything else we can think of │
│Date-Time│14/05/93 00:28:41 │
│Copyright│L&W Computer Services Ltd. │
│ Author│Darren Lancaster │
└─────────┴────────────────────────────────────────────────────────────────┘
*/
CREATE CLASS Window
METHOD SayColor, WhoAmI
EXPORT:
VAR Cargo
VAR nTop, nLeft, nHeight, nWidth, nBottom, nRight,;
MaxRow, MaxCol, nRow, nCol TYPE NUMERIC
VAR cWindow, cOldScreen, cTitle, cTitleColor, cBackColor,;
cOffColor TYPE CHARACTER
VAR lCanBeSeen, lFocus, lDisplayed TYPE LOGICAL
CLASS VAR aStack TYPE ARRAY
MESSAGE aStack TO CLASS
METHOD Init, Display, Hide, Show, Close, paint, Title, HideAll, HideWindow,;
ShowWindow, SaveFront, RestFront, Say, SayC, DrawAll, Clear, DispWindow
MESSAGE SetPos METHOD Pos
CLASS METHOD CloseAll
END CLASS
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│init(nTop, nLeft, nHeight, nWidth, cTitle) │
│ Purpose│This method is used to set up all the vars for the object │
│ │ │
│ │ nTop : the top row, where the window will start │
│ │ nLeft : the left column, where the window will start │
│ │ nHeight : the number of rows that the window uses │
│ │ nWidth : the number of columns the window takes up │
│ │ cTitleColor : the Title header color for the window │
│ │ cBackColor : the Window pane color │
│ │ cTitle : the text to diaplay in the title bar │
│ │ lCanBeSeen : is the window being displayed │
│ │ aStack : stack used to hold window number and position │
│ │ lFocus : is the window the output window │
│ │ │
│ │ │
│Date-Time│14/05/93 00:28:45 │
│Copyright│L&W Computer Services Ltd. │
│ Author│Darren Lancaster │
└─────────┴────────────────────────────────────────────────────────────────┘
*/
METHOD init(nTop, nLeft, nHeight, nWidth, cTitle)
IF nTop != NIL .AND. nLeft != NIL .AND. ValType(nHeight) != "N"
cTitle := nHeight
nHeight := nTop
nWidth := nLeft
nTop := NIL
nLeft := NIL
ENDIF
IF nTop == NIL
nTop := MaxRow() / 2 - (nHeight + 4) / 2
ENDIF
IF nLeft == NIL
nLeft := MaxCol() / 2 - (nWidth + 2) / 2
ENDIF
IF nWidth < 1
nWidth := 1
ENDIF
IF nHeight < 1
nHeight := 1
ENDIF
::nTop := Int(nTop)
::nLeft := Int(nLeft)
::nHeight := Int(nHeight)
::nWidth := Int(nWidth)
::cOffColor := "W+"
::cTitleColor := "GR+"
::cBackColor := "B"
::cTitle := If( !Empty(cTitle), cTitle,"")
::lCanBeSeen := ::lDisplayed := .F.
IF VALTYPE(::aStack) != "A"
:: class:aStack := {}
ENDIF
aAdd(:: class:aStack, self)
::lFocus := .F.
::nBottom := Int(nTop + nHeight + 3)
::nRight := Int(nLeft + nWidth + 1)
::nRow := ::nCol := 0
::MaxRow := nHeight - 1
::MaxCol := nWidth - 1
RETURN self
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│close │
│ Purpose│To remove the window from the stack and the display │
│Date-Time│14/05/93 00:28:48 │
│Copyright│L&W Computer Services Ltd. │
│ Author│Darren Lancaster │
└─────────┴────────────────────────────────────────────────────────────────┘
*/
METHOD Close
@:Hide()
aDel(::aStack, @:WhoAmI())
aSize(::aStack, LEN(::aStack)-1)
RETURN self
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│WhoAmI() --> <nWindowNumber> │
│ Purpose│Which window am I? │
│Date-Time│05-24-93 09:55:42pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD WhoAmI
RETURN (aScan(::aStack, {|oWindow| oWindow == self }))
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│Display([<lFocus>]) --> self │
│ Purpose│to draw a new window on the screen. Save the background first │
│ │draw the box, draw the title │
│Date-Time│14/05/93 00:28:55 │
│Copyright│L&W Computer Services Ltd. │
│ Author│Darren Lancaster │
└─────────┴────────────────────────────────────────────────────────────────┘
*/
METHOD Display(lFocus)
LOCAL oTemp, cSetColor
IF ::lDisplayed
@:Show()
ELSE
IF ValType(lFocus) != "L"
lFocus := .T.
ENDIF
IF !::lFocus
IF LEN(::aStack) > 1
IF lFocus
oTemp := ::aStack[LEN(::aStack) - 1]
oTemp:lFocus := .F.
cSetColor := SetColor(oTemp:cOffColor + "/" + oTemp:cBackColor)
SetColor(cSetColor)
oTemp:SaveFront()
ELSE
oTemp := Atail(::aStack)
aIns(::aStack, Len(::aStack) - 1)
::aStack[Len(::aStack) - 1] := oTemp
ENDIF
ENDIF
ENDIF
::cOldScreen := SaveScreen(::nTop, ::nLeft, ::nBottom, ::nRight)
::lCanBeSeen := .T.
::lFocus := lFocus
@:Paint()
::lDisplayed := .T.
ENDIF
RETURN self
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│Paint() --> self │
│ Purpose│Paint the window │
│Date-Time│05-19-93 11:51:13am │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD Paint
LOCAL cColor
IF ::lCanBeSeen
DispBegin()
cColor := SetColor(If(::lFocus, ::cTitleColor, ::cOffColor) + "/" + ::cBackColor)
::DispWindow(.T.)
@:Title()
::cWindow := ""
SetColor(cColor)
DispEnd()
ENDIF
RETURN (self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│Title() --> self │
│ Purpose│Display the Title │
│Date-Time│05-19-93 12:01:10pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD Title()
IF ::lCanBeSeen
@ ::nTop + 1, ::nLeft + 1 SAY PadC(::cTitle, ::nWidth) COLOR ::cTitleColor + "/" + ::cBackColor
ENDIF
RETURN (self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│show │
│ Purpose│to show a window that has been hidden │
│Date-Time│14/05/93 00:28:53 │
│Copyright│L&W Computer Services Ltd. │
│ Author│Darren Lancaster │
└─────────┴────────────────────────────────────────────────────────────────┘
*/
METHOD Show
LOCAL nX := 0, nWhoAmI := 0
DispBegin()
@:HideAll()
FOR nX := 1 TO LEN(:: class:aStack)
IF !(:: class:aStack[nX] == self)
:: class:aStack[nX]:lFocus := .F.
ELSE
nWhoAmI := nX
ENDIF
NEXT
::lFocus := .T.
::lCanBeSeen := .T.
ADEL(:: class:aStack, nWhoAmI)
:: class:aStack[ LEN(:: class:aStack) ] := self
@:DrawAll()
DispEnd()
RETURN self
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│Hide │
│ Purpose│to restore the background and hide the window │
│Date-Time│14/05/93 00:28:59 │
│Copyright│L&W Computer Services Ltd. │
│ Author│Darren Lancaster │
└─────────┴────────────────────────────────────────────────────────────────┘
*/
METHOD Hide
LOCAL nX, nWhoIsFocus := 0, oTemp
IF ::lCanBeSeen
DispBegin()
@:HideAll()
::lCanBeSeen := .F.
::lFocus := .F.
FOR nX := 1 TO Len(::aStack)
IF ::aStack[nX]:lCanBeSeen
nWhoIsFocus := nX
ENDIF
::aStack[nX]:lFocus := .F.
NEXT nX
IF nWhoIsFocus > 0
::aStack[nWhoIsFocus]:lFocus := .T.
oTemp := ::aStack[nWhoIsFocus] // Move newly focussed widow to top
aDel(::aStack, nWhoIsFocus)
::aStack[Len(::aStack)] := oTemp
ENDIF
@:DrawAll()
DispEnd()
ENDIF
RETURN self
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│HideAll() --> self │
│ Purpose│Hide all the windows in the right order │
│Date-Time│05-19-93 12:21:18pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD HideAll
LOCAL nX
FOR nX := Len(::aStack) TO 1 STEP -1
IF ::aStack[nX]:lCanBeSeen
::aStack[nX]:HideWindow()
ENDIF
NEXT nX
RETURN(Self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│DrawAll() --> self │
│ Purpose│Draw all of the windows │
│Date-Time│05-19-93 11:24:14am │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD DrawAll
LOCAL nX
FOR nX := 1 TO Len(::aStack)
IF ::aStack[nX]:lCanBeSeen
::aStack[nX]:ShowWindow()
ENDIF
NEXT nX
RETURN (self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│HideWindow() --> self │
│ Purpose│Save the image of the window and hide it │
│Date-Time│05-19-93 12:30:18pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD HideWindow
IF ::lCanBeSeen
@:SaveFront()
RestScreen(::nTop, ::nLeft, ::nBottom, ::nRight, ::cOldScreen)
ENDIF
RETURN (self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│ShowWindow │
│ Purpose│Restore the window back to the screen │
│Date-Time│05-19-93 12:31:57pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD ShowWindow
LOCAL cSetColor := SetColor(If(::lFocus, ::cTitleColor, ::cOffColor) + "/" + ::cBackColor)
::cOldScreen := SaveScreen(::nTop, ::nLeft, ::nBottom, ::nRight)
@:RestFront()
SetColor(cSetColor)
RETURN (self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│SaveFront() --> self │
│ Purpose│Save the image of the window │
│Date-Time│05-19-93 12:40:05pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD SaveFront
IF ::lCanBeSeen
::cWindow := SaveScreen(::nTop, ::nLeft, ::nBottom, ::nRight)
ENDIF
RETURN (self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│RestFront() --> self │
│ Purpose│Restore the image of the window │
│Date-Time│05-19-93 12:40:42pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD RestFront
IF ::lCanBeSeen
RestScreen(::nTop, ::nLeft, ::nBottom, ::nRight, ::cWindow)
ENDIF
RETURN (self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│SetPos([<nRow>], [<nCol>]) --> self │
│ Purpose│Position the windows' cursor │
│Date-Time│05-19-93 12:50:03pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD Pos(nRow, nCol)
::nRow := If(ValType(nRow) == "N", Min(nRow, ::MaxRow), ::nRow)
::nCol := If(ValType(nCol) == "N", Min(nCol, ::MaxCol), ::nCol)
RETURN (self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│Say(<cString>, [<cForColour>]) --> self │
│ Purpose│Display a string in the window │
│Date-Time│05-19-93 12:52:31pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD Say(cString, cColour)
@ ::nRow + ::nTop + 3, ::nCol + ::nLeft + 1 SAY Left(cString, ::nRight - (::nCol + ::nLeft) - 1) COLOR ::SayColor(cColour)
::nCol += Len(cString)
RETURN (self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│SayColour(<cColour>) --> <cFullColour> │
│ Purpose│Get the complete colour string worked out │
│Date-Time│05-19-93 01:58:41pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD SayColor(cColour)
IF ValType(cColour) != "C"
cColour := "GR+/" + ::cBackColor
ELSEIF !("/" $ cColour)
cColour += "/" + ::cBackColor
ENDIF
RETURN(cColour)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│SayC(<cString>, [<cColour>]) --> self │
│ Purpose│Display a centred string in the window │
│Date-Time│05-19-93 12:57:10pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD SayC(cString, cColour)
::nCol := 0
@:Say(PadC(cString, ::MaxCol + 1), cColour)
RETURN (self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│Clear() --> self │
│ Purpose│Clear area of window │
│Date-Time│05-27-93 02:55:04pm │
│Copyright│L&W Computer Services Ltd. │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD Clear
@ ::nTop + 3, ::nLeft + 1 CLEAR TO ::nBottom - 1, ::nRight - 1
RETURN (self)
/*┌─────────┬────────────────────────────────────────────────────────────────┐
│ Method│ │
│ Purpose│ │
│Date-Time│07-09-93 09:07:43pm │
│Copyright│AWE&BS Ltd │
│ Author│Ian Day │
└─────────┴────────────────────────────────────────────────────────────────┘*/
METHOD CloseAll
@:HideAll()
::aStack := {}
RETURN (self)
/*┌─ Method ─────────────────────────────────────────────────────────────────┐
│ Name: DispWindow() │
│ Description: Draw a window │
│ Author: Darren Lancaster │
│ Date created: 29-06-94 Date updated: ■29-06-94 │
│ Time created: 11:53:31am Time updated: ■11:53:31am │
│ Copyright: L&W Computer Services Ltd │
└──────────────────────────────────────────────────────────────────────────┘
*/
METHOD DispWindow(lClear)
IF lClear
Scroll (::nTop, ::nLeft, ::nBottom, ::nRight, 0, 0)
ENDIF
DispBox(::nTop, ::nLeft, ::nBottom, ::nRight, B_DOUBLE)
@ ::nTop+2, ::nLeft SAY "╠"
@ ::nTop+2, ::nRight SAY "╣"
DispBox(::nTop+2, ::nLeft+1, ::nTop+2, ::nRight-1, B_DOUBLE)
RETURN(self)